# frozen_string_literal: true

class CreateRuleVersions < ActiveRecord::Migration[6.0]
  def change
    create_table :rule_versions do |t|
      t.integer   :rule_id,     null: false,  limit: 8
      t.integer   :version,     null: false,  limit: 4
      t.datetime  :start_time,  null: false
      t.datetime  :end_time,    null: true
      t.text      :schema,      null: false,  limit: 0xffffff
      t.text      :content,     null: false,  limit: 0xffffffff
      t.timestamps              null: false
    end

    add_index :rule_versions, %i[version rule_id], unique: true
    add_foreign_key :rule_versions, :rules
  end
end
